<?php

namespace app\common\service;


use app\common\model\LogModel;
use Think\Exception;

class LogInfoService extends BaseService
{
    public $logModel;
    public function __construct()
    {
        $this->logModel=new LogModel();
    }

    public static $errorType_addressError='addressError';//收货地址错误日志
    public static $errorType_cartError='cartError';//购物车错误日志
    public static $errorType_expressError='expressError';//物流错误日志
    public static $errorType_orderError='orderError';//订单错误日志
    public static $errorType_wxPayNotify='wxPayNotify';//微信支付回调日志
    public static $errorType_indexError='indexError';//商城首页错误日志
    public static $errorType_Exception='Exception';//php自动补获异常

    public static function typeAll(){
        return array(
            self::$errorType_addressError=>'addressError',//收货地址错误日志
            self::$errorType_cartError=>'cartError',//购物车错误日志
            self::$errorType_expressError=>'expressError',//物流错误日志
            self::$errorType_orderError=>'orderError',//订单错误日志
            self::$errorType_wxPayNotify=>'wxPayNotify',//微信支付回调日志
            self::$errorType_indexError=>'indexError',//商城首页错误日志
            self::$errorType_Exception=>'Exception',//php自动补获异常
        );
    }

    public function writeLog($type,$info,$data=null,$remark=null){
        try{
            $add['type']=$type;
            $add['info']=$info;
            $add['data']=json_encode($data);
            $add['create_time']=date('Y-m-d H:i:s');
            $add['api']=$_SERVER['REQUEST_URI'];
            $add['remark']=json_encode($remark);
            $this->logModel->save($add);
        }catch (Exception $ex){
            $addEx['type']='Exception';
            $addEx['info']=$ex->getMessage();
            $addEx['data']=json_encode($add);
            $addEx['create_time']=date('Y-m-d H:i:s');
            $add['api']=$_SERVER['REQUEST_URI'];
            $this->logModel->save($addEx);
        }
    }


}